package com.topnav.mc.document.entity.bean;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.topnav.mc.document.entity.Document;
import com.topnav.mc.document.entity.enums.EnumDocImportance;
import com.topnav.mc.document.entity.enums.EnumDocType;
import lombok.Data;

import java.util.Date;

/**
 * @Author: kenny
 * @Date: 2023/11/23 13:39
 */
@Data
public class DocumentBean extends Document {
    private String orgCode;
    private String shortName;
    private String orgName;
    private String path;

    private String userCode;
    private String userName;

    private String importanceDesc;
    private String docTypeDesc;
    private String fileSizeDesc;
    private String durationDesc;
    private String siteCode;
    private String siteName;
    private String siteHost;
    private String sitePort;
    private String siteUrl;

    private String deviceCode;
    private String deviceName;
    private String playUrl;

    //原JsonFormat 已用注解 上传保存时会报错，不能读参数，所以改用这个
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date expireTimeShow;


    public String getImportanceDesc(){
        return EnumDocImportance.getDescByCode(this.getImportance());
    }

    public String getDocTypeDesc(){
        return EnumDocType.getDescByCode(this.getImportance());
    }

    public String getFileSizeDesc(){
        if (this.getFileSize() == null||this.getFileSize().equals(0L)){
            return "0MB";
        }
        return String.valueOf(Math.round(this.getFileSize()/1024.00/1024.00*100.00)/100.00) + "MB";
    }

    public String getDurationDesc(){
        if (this.getDuration() == null||this.getDuration().equals(0L)){
            return "0秒";
        }

        long d1=this.getDuration()/1000L;
        long h=d1/(60*60);
        d1=d1%(60*60);
        long m=d1/60;
        long s=d1%60;
        String str = "";
        if (h>0)str = str + h+"小时";
        if (m>0)str = str + m+"分";
        if (s>0)str = str + s+"秒";
        return str;

    }

    public String getPlayUrl(){
        return this.getSiteUrl() + "/" + this.getDocUri() + "/" + this.getDocName();
    }

    public Date getExpireTimeShow(){
        return getExpireTime();
    }

}
